Skip to content

[Xamarin.Android.Build.Tasks] Skip library proguard.txt with disallowed global options - #11709

Merged
simonrozsival merged 2 commits into
mainfrom
jonathanpeppers-vigilant-funicular
Jun 23, 2026
Merged

[Xamarin.Android.Build.Tasks] Skip library proguard.txt with disallowed global options#11709
simonrozsival merged 2 commits into
mainfrom
jonathanpeppers-vigilant-funicular

Conversation

@jonathanpeppers

Copy link
Copy Markdown
Member

Fixes/aligns with the behavior introduced in Android Gradle Plugin 9.0:

From AGP 9.0, Android library and feature module publishing will fail if consumer keep files contain problematic Proguard configurations. Consumer keep files that include global options like -dontoptimize or -dontobfuscate should only be used in application modules, and can reduce optimization benefits for library users. Android App module compilation will silently ignore any such global options if embedded in a pre-compiled dependency (JAR or AAR).

The same restriction applies to R8 for options that control where build outputs go — -printmapping, -printconfiguration, -printusage, -printseeds, -dump. When a third-party .aar (or NuGet package wrapping one) ships a proguard.txt with one of those directives, current dotnet build either:

  • fails the R8 invocation, or
  • writes mapping/usage files to the path the library author chose (silently overwriting the location the app project requested).

Change

In R8.cs, after ResolveLibraryProjectImports has extracted each .aar's proguard.txt, scan the file (only for items that carry the OriginalFile metadata — i.e. library-provided files, not ones we generate or the user added). If any disallowed global option is present:

  • the whole file is skipped — it is not passed to R8 with --pg-conf, and
  • a new XA4322 warning is emitted naming the source: NuGet package id + version when available, otherwise the .aar path.

Example warning:

warning XA4322: Skipping library ProGuard configuration file 'obj/Debug/net10.0-android/lp/0/jl/proguard.txt' (from NuGet package 'Acme.SomeLibrary' 1.2.3) because it contains the unsupported global option '-printmapping'. Global ProGuard options are only allowed in application projects.

User-authored <ProguardConfiguration Include="..." /> items in the app project, and the SDK-generated configs (proguard_xamarin.cfg, proguard_project_primary.cfg, etc.) are left untouched.

Notes

  • The ProguardConfigurationFiles parameter on the R8 task changed from string[] to ITaskItem[] so we can read the OriginalFile/NuGetPackageId/NuGetPackageVersion metadata that ResolveLibraryProjectImports already attaches. No targets needed updating — @(_ProguardConfiguration) / @(ProguardConfiguration) already flow through as items.
  • This is more aggressive than AGP, which silently strips just the offending lines. The simpler "skip whole file + warn" was preferred over rewriting library files to a temp location. The XA4322 doc page describes the workaround (add equivalent -keep rules to the app's own ProguardConfiguration) for users blocked on a 3rd-party library fix.

Tests

  • New R8Tests.TryGetDisallowedOption parametric unit test covers each option, leading whitespace (spaces and tabs), comments, empty lines, and case-insensitive matching.
  • Manual end-to-end verification can be done by adding -printmapping out.txt to any AAR's proguard.txt and observing the XA4322 warning instead of the build failure / silent mapping override.

…ed global options

Android Gradle Plugin 9.0 disallows `global'' ProGuard options such as -printmapping, -printconfiguration, -printusage, -printseeds, and -dump in consumer keep files shipped inside an .aar. AGP either fails library publishing or silently strips the options when consuming a pre-built dependency:

https://developer.android.com/build/releases/agp-9-0-0-release-notes#behavior-changes

Bring the same protection to .NET for Android: when an .aar's proguard.txt (extracted by ResolveLibraryProjectImports) contains one of these options, skip the whole file when invoking R8 and emit a new XA4322 warning naming the NuGet package (or .aar path) the configuration came from. Files generated by us or added directly by the user are untouched.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers
jonathanpeppers marked this pull request as ready for review June 22, 2026 17:14
Copilot AI review requested due to automatic review settings June 22, 2026 17:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the R8 MSBuild task to align with AGP 9.0 behavior by detecting and skipping library-provided proguard.txt files that contain disallowed global ProGuard options, emitting a new XA4322 warning to keep builds reliable and avoid unintended output redirection.

Changes:

  • Change R8.ProguardConfigurationFiles from string[] to ITaskItem[] so metadata (OriginalFile, NuGetPackageId, NuGetPackageVersion) can be used to identify library-provided configs.
  • Add scanning logic in R8.cs to skip offending library proguard.txt files and log XA4322.
  • Add XA4322 resources + documentation, and a unit test for option detection.

Reviewed changes

Copilot reviewed 5 out of 6 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/Xamarin.Android.Build.Tasks/Tests/Xamarin.Android.Build.Tests/Tasks/R8Tests.cs Adds unit tests for TryGetDisallowedOption parsing.
src/Xamarin.Android.Build.Tasks/Tasks/R8.cs Implements library proguard option detection + warning emission; switches config input to ITaskItem[].
src/Xamarin.Android.Build.Tasks/Properties/Resources.resx Adds localized message text for XA4322.
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs Adds generated accessor for XA4322.
Documentation/docs-mobile/messages/xa4322.md Adds a new warning documentation page for XA4322.
Documentation/docs-mobile/messages/index.md Adds XA4322 to the messages index.
Files not reviewed (1)
  • src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs: Generated file

Comment thread src/Xamarin.Android.Build.Tasks/Tasks/R8.cs
Comment thread src/Xamarin.Android.Build.Tasks/Tasks/R8.cs
Comment thread Documentation/docs-mobile/messages/xa4322.md
…heck

Per the AGP 9.0 release notes, the primary global options called out are -dontoptimize and -dontobfuscate. Add them to DisallowedLibraryProguardOptions so libraries cannot silently disable optimization/obfuscation for consuming apps.

Also tighten TryGetDisallowedOption to require an end-of-token boundary (end-of-line or whitespace) after the matched option, so e.g. '-printmappingFoo' is no longer wrongly treated as '-printmapping'. Tests cover both new options and the boundary case.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Jun 22, 2026
@simonrozsival
simonrozsival merged commit 10d0529 into main Jun 23, 2026
40 checks passed
@simonrozsival
simonrozsival deleted the jonathanpeppers-vigilant-funicular branch June 23, 2026 10:24
davidortinau added a commit to dotnet/core that referenced this pull request Jul 10, 2026
Incorporates jfversluis review feedback on #10467:
- Android MediaPicker result recovery APIs (dotnet/maui#35455)
- HybridWebView Android message-source filtering (dotnet/maui#35717)
- XAML C# expression source generator CS1061 fix (dotnet/maui#35922)
- Testable permissions via IPermissions/Permissions.Current (dotnet/maui#35987)
- XA0149 warning for legacy __AndroidEnvironment__ resources (dotnet/android#11700)
- Skip library proguard.txt with disallowed R8 global options (dotnet/android#11709)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
davidortinau added a commit to dotnet/core that referenced this pull request Jul 10, 2026
* [release-notes] .NET MAUI in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Draft .NET MAUI and friends notes for .NET 11 Preview 6

Combined highlights for .NET MAUI, .NET for Android, and .NET for iOS,
Mac Catalyst, macOS, and tvOS: CollectionView2 on Windows, handler-based
Shell on Android, Compatibility package removal, AOT-safe HybridWebView,
Geolocation minimum-distance filter, a reliability wave, the
AndroidMessageHandler HTTP-contract work, and the Apple platform toolchain
and NSUrlSessionHandler updates.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Add Preview 6 items from MAUI maintainer review

Incorporates jfversluis review feedback on #10467:
- Android MediaPicker result recovery APIs (dotnet/maui#35455)
- HybridWebView Android message-source filtering (dotnet/maui#35717)
- XAML C# expression source generator CS1061 fix (dotnet/maui#35922)
- Testable permissions via IPermissions/Permissions.Current (dotnet/maui#35987)
- XA0149 warning for legacy __AndroidEnvironment__ resources (dotnet/android#11700)
- Skip library proguard.txt with disallowed R8 global options (dotnet/android#11709)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: David Ortinau <david.ortinau@microsoft.com>
rbhanda added a commit to dotnet/core that referenced this pull request Jul 14, 2026
* [release-notes] .NET 11 Preview 6 base metadata

changes.json, features.json, build-metadata.json, and README for the
.NET 11 Preview 6 milestone (VMR base v11.0.0-preview.5.26302.115 ->
head release/11.0.1xx-preview6).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* [release-notes] C# in .NET 11 Preview 6 (#10460)

* [release-notes] C# in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Update release-notes/11.0/preview/preview6/csharp.md

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Bill Wagner <wiwagn@microsoft.com>

* [release-notes] MSBuild in .NET 11 Preview 6 (#10463)

* [release-notes] MSBuild in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Add bug-fix note for architecture-agnostic Runtime=NET task host handshake (dotnet/msbuild#13890)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Remove HTML comments from Preview 6 MSBuild release notes

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Chet Husk <chusk3@gmail.com>

* [release-notes] NuGet in .NET 11 Preview 6 (#10464)

* [release-notes] NuGet in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix STJ feature-flag env var value and remove VS reference

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Chet Husk <chusk3@gmail.com>

* [release-notes] .NET SDK in .NET 11 Preview 6 (#10459)

* [release-notes] .NET SDK in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Clarify NativeAOT CLI updates in preview6/sdk.md

Updated the NativeAOT CLI section to clarify the unification of managed and NativeAOT parsers, and removed filtered content related to internal changes.

* Add live running-tests display to dotnet test notes

Document the in-flight test progress panel (dotnet/sdk#54486) and fix
pre-existing trailing-space lint errors in the NativeAOT section.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Chet Husk <baronfel@users.noreply.github.com>
Co-authored-by: Chet Husk <chusk3@gmail.com>

* [release-notes] Windows Forms in .NET 11 Preview 6 (#10465)

* [release-notes] Windows Forms in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Revise Windows Forms release notes for Preview 6

Updated release notes for .NET 11 Preview 6 to include bug fixes and improvements for various Windows Forms components.

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Klaus Löffelmann <9663150+KlausLoeffelmann@users.noreply.github.com>

* [release-notes] .NET MAUI in .NET 11 Preview 6 (#10467)

* [release-notes] .NET MAUI in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Draft .NET MAUI and friends notes for .NET 11 Preview 6

Combined highlights for .NET MAUI, .NET for Android, and .NET for iOS,
Mac Catalyst, macOS, and tvOS: CollectionView2 on Windows, handler-based
Shell on Android, Compatibility package removal, AOT-safe HybridWebView,
Geolocation minimum-distance filter, a reliability wave, the
AndroidMessageHandler HTTP-contract work, and the Apple platform toolchain
and NSUrlSessionHandler updates.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

* Add Preview 6 items from MAUI maintainer review

Incorporates jfversluis review feedback on #10467:
- Android MediaPicker result recovery APIs (dotnet/maui#35455)
- HybridWebView Android message-source filtering (dotnet/maui#35717)
- XAML C# expression source generator CS1061 fix (dotnet/maui#35922)
- Testable permissions via IPermissions/Permissions.Current (dotnet/maui#35987)
- XA0149 warning for legacy __AndroidEnvironment__ resources (dotnet/android#11700)
- Skip library proguard.txt with disallowed R8 global options (dotnet/android#11709)

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: David Ortinau <david.ortinau@microsoft.com>

* [release-notes] EF Core in .NET 11 Preview 6 (#10462)

Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>

* [release-notes] F# in .NET 11 Preview 6 (#10461)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* [release-notes] Containers in .NET 11 Preview 6 (#10468)

* [release-notes] Containers in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Update release notes

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Logan Bussell <loganbussell@microsoft.com>

* [release-notes] .NET Libraries in .NET 11 Preview 6 (#10457)

* [release-notes] .NET Libraries in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix async DataAnnotations sample after testing on the Preview 6 SDK

AsyncValidationAttribute is overridden via the protected IsValidAsync
(and IsValid) members, not GetValidationResultAsync (which is the public
method the framework calls and is not virtual). Verified the corrected
sample compiles and runs against the Preview 6 build.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Verify Preview 6 library samples and fix inaccuracies

- Stream adapters: read from the read-only stream via StreamContent/PostAsync instead of copying HttpContent into it

- Cross-lane vectors: replace nonexistent Concat with ConcatLowerLower/LowerUpper/UpperLower/UpperUpper and drop preexisting Shuffle/ShuffleNative

- Async validation: swap the unique-username example for a VAT registry lookup, layer StringLength and RegularExpression sync rules with the async rule, and add a server-side validation note

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>

* [release-notes] ASP.NET Core in .NET 11 Preview 6 (#10456)

* [release-notes] WPF in .NET 11 Preview 6 (#10466)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Throw InvalidOperationException for sync validation of async validator

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>

* Apply late review suggestions from #10456 to the ASP.NET Core notes

- OpenAPI unions: correct the third-party generator claim (ApiExplorer does not
  detect unions via JsonTypeInfoKind.Union; Swashbuckle/NSwag don't yet
  recognize unions). Per @DeagleGross review on #10456.
- Blazor Virtualize: note that a user scroll during ScrollToIndexAsync wins.
  Per @ilonatommy review on #10456.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Add P6 Blazor items to align with docs (dotnet/AspNetCore.Docs#37322)

- CSRF: note that Blazor Web App templates no longer call app.UseAntiforgery().
- Bug fixes/Blazor: Virtualize is now CSP-compliant (#66680); session cookie is
  issued before streaming SSR for [SupplyParameterFromSession]/TempData (#66832).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Document 'Configure Blazor client behavior from the server' as a P6 feature

WithBrowserOptions flows client-side Blazor.start configuration from the server
in C# (log level, Server reconnection, SSR DOM preservation, WASM environment),
serialized to the client across Server/WebAssembly/Auto render modes. Introduced
in Preview 4 (server-to-browser config via DOM comment) and reshaped in Preview 6
(dotnet/aspnetcore#67337, proposal #66393). Includes the reshape/rename migration
for earlier adopters. Sample build-verified on 11.0.100-preview.6.26359.118.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Correct Virtualize CSP note: data-blazor-virtualize-reserved-height

Reviewing dotnet/AspNetCore.Docs#37322 surfaced that the attribute is
data-blazor-virtualize-reserved-height (only the server-computed spacer height),
not the generic data-blazor-style. Verified in the P6 source (Virtualize.cs /
Virtualize.ts). @ilonatommy corrected the same wording on the docs PR.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* [release-notes] .NET Runtime in .NET 11 Preview 6 (#10458)

* [release-notes] .NET Runtime in .NET 11 Preview 6

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Enrich Preview 6 runtime notes with additional verified features

Fold verified .NET 11 Preview 6 runtime changes into runtime.md
(JIT improvements, in-process crash logging, NativeAOT interface
dispatch, SIMD lane APIs, and an expanded bug-fix list), and rebuild
the TOC to match the current sections.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ade796bb-8052-4946-b204-a88518267e77

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Rich Lander <2608468+richlander@users.noreply.github.com>

* fix markdown lint in preview6 containers note

Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>

---------

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Bill Wagner <wiwagn@microsoft.com>
Co-authored-by: Chet Husk <chusk3@gmail.com>
Co-authored-by: Chet Husk <baronfel@users.noreply.github.com>
Co-authored-by: Klaus Löffelmann <9663150+KlausLoeffelmann@users.noreply.github.com>
Co-authored-by: David Ortinau <david.ortinau@microsoft.com>
Co-authored-by: AndriySvyryd <6539701+AndriySvyryd@users.noreply.github.com>
Co-authored-by: Logan Bussell <loganbussell@microsoft.com>
Co-authored-by: Jeff Handley <jeffhandley@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Rich Lander <2608468+richlander@users.noreply.github.com>
Co-authored-by: Rahul Bhandari <rbhanda@microsoft.com>
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jongalloway <68539+jongalloway@users.noreply.github.com>
@github-actions github-actions Bot locked and limited conversation to collaborators Jul 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants